<template>
  <div class="order">
    <div class="type">
      <span class="iconfont" @click="goto()">&#xe779;</span>
      订单列表
    </div>
    <div class="tab">
      <ul>
        <li @click="myi(0, '待付款')">
          <router-link to="" :class="index == 0 ? 'active' : ''"
            >待付款</router-link
          >
        </li>
        <li @click="myi(1, '待发货')">
          <router-link to="" :class="index == 1 ? 'active' : ''"
            >待发货</router-link
          >
        </li>
        <li @click="myi(2, '待收货')">
          <router-link to="" :class="index == 2 ? 'active' : ''"
            >待收货</router-link
          >
        </li>
        <li @click="myi(3, '已完成')">
          <router-link to="" :class="index == 3 ? 'active' : ''"
            >已完成</router-link
          >
        </li>
        <li @click="myi(4, '已完成')">
          <router-link to="" :class="index == 4 ? 'active' : ''"
            >售后</router-link
          >
        </li>
      </ul>
    </div>
    <div class="isture" v-if="is">
      <p>还没有该订单哦~</p>
    </div>
    <div class="xinxi">
      <div class="dd" v-for="item1 in dd">
        <div class="bianhao">
          <p>平台运营</p>
          <div class="bh">
            <p>订单号:{{ item1.ddh }}</p>
            <span>{{ item1.sj }}</span>
          </div>
        </div>
        <div class="sp" v-for="item in item1">
          <div class="left">
            <img :src="item.img" alt="" />
          </div>
          <div class="right">
            <p>{{ item.name }}</p>
            <div class="gg">
              <span v-if="item.gg">规格:{{ item.gg }}</span>
              <span v-if="item.ys">颜色:{{ item.ys }}</span>
            </div>
            <div class="bot">
              <p>x{{ item.sl }}</p>
              <span>￥:{{ item.jg * item.sl }}</span>
            </div>
          </div>
        </div>
        <div class="hj">
          <p>合计：￥{{ hj }}</p>
          <div class="right">
            <button>取消</button>
            <button>{{ item1[0].fh }}</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.order {
  width: 100%;
  overflow: hidden;
  .type {
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 9999;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    color: rgb(116, 116, 116);
    text-align: center;
    background-color: white;
    span {
      position: absolute;
      display: block;
      height: 50px;
      width: 40px;
    }
    a {
      display: block;
      span {
        position: absolute;
        display: block;
        height: 50px;
        color: rgb(116, 116, 116);
        font-size: 25px;
        width: 40px;
        right: 0;
        top: 0;
      }
    }
  }
  .tab {
    position: fixed;
    top: 50px;
    z-index: 99999;
    width: 100%;
    background-color: white;
    ul {
      display: flex;
      justify-content: space-around;
      width: 100%;
      li {
        a {
          display: block;
          height: 50px;
          font-size: 16px;
          line-height: 50px;
        }
      }
      .active {
        border-bottom: 1px solid red;
        color: red;
      }
    }
  }
  .xinxi {
    margin-top: 100px;
    margin-bottom: 60px;
    .dd {
      margin-top: 10px;
      .bianhao {
        padding: 10px;
        border-bottom: 1px solid #ccc;
        border-top: 1px solid #ccc;
        > p {
          font-size: 14px;
          line-height: 20px;
          color: rgb(116, 116, 116);
        }
        .bh {
          position: relative;
          p {
            padding-top: 10px;
            line-height: 20px;
            font-size: 13px;
            color: rgb(116, 116, 116);
          }
          span {
            position: absolute;
            right: 0px;
            top: 14px;
            font-size: 13px;
            color: rgb(116, 116, 116);
          }
        }
      }
      .sp {
        padding: 15px 0;
        display: flex;
        border-bottom: 1px solid #ccc;
        .left {
          width: 90px;
          padding-left: 15px;
          height: 90px;
          img {
            width: 90px;
            max-height: 90px;
            margin: 0 auto;
          }
        }
        .right {
          margin: 0 10px;
          > p {
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            color: rgb(82, 82, 82);
            line-height: 20px;
            font-size: 15px;
          }
          .gg {
            margin-top: 5px;
            span {
              color: rgb(82, 82, 82);
              font-size: 12px;
            }
          }
          .bot {
            margin-top: 25px;
            position: relative;
            p {
              color: rgb(82, 82, 82);
              font-size: 14px;
            }
            span {
              position: absolute;
              right: 0;
              font-size: 14px;
              color: red;
              top: 0;
            }
          }
        }
      }
      .hj {
        padding: 10px;
        position: relative;
        border-bottom: 1px solid #ccc;
        p {
          font-size: 16px;
          line-height: 40px;
          color: rgb(116, 116, 116);
        }
        .right {
          display: flex;
          position: absolute;
          right: 10px;
          top: 10px;
          button {
            background-color: white;
            display: block;
            padding: 10px 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-left: 10px;
          }
        }
      }
    }
  }
  .isture {
    margin-top: 200px;
    text-align: center;
    p {
      color: red;
    }
  }
}
</style>
<script>
import { mapState } from "vuex";
export default {
  name: "order",
  data() {
    return {
      index: 0,
      dd: [],
      hj: 0,
      is: true,
    };
  },
  methods: {
    goto() {
      this.$router.go(-1);
    },
    myi(i, str) {
      this.index = i;
      this.$store.state.zt = str;
    },
  },
  computed: {
    ...mapState(["zt", "dingdan"]),
  },
  mounted() {
    if (this.dingdan.length > 0) {
      for (let i = 0; i < this.dingdan.length; i++) {
        if (this.dingdan[i][0].fh == this.zt) {
          this.dd.push(this.dingdan[i]);
        }
      }
    }
    if (this.dd.length > 0) {
      this.is = false;
    } else {
      this.is = true;
    }
  },
  beforeUpdate() {
    this.dd = [];
    this.hj = 0;
    if (this.dingdan.length > 0) {
      for (let i = 0; i < this.dingdan.length; i++) {
        if (this.dingdan[i][0].fh == this.zt) {
          this.dd.push(this.dingdan[i]);
        }
      }
      if (this.dd.length > 0) {
        for (let j = 0; j < this.dd[0].length; j++) {
          this.hj += this.dd[0][j].jg * this.dd[0][j].sl;
        }
      }
    }
    if (this.dd.length > 0) {
      this.is = false;
    } else {
      this.is = true;
    }
  },
};
</script>